import { observable, action } from 'mobx';
import { Tools } from 'weaver-mobile';
import { ListViewPage } from 'weaver-mobile-page';

export default class DefalutJoinerStore {
  path;
  @observable defalutJoinerList;
  @observable listLoading = true;

  @action setStoreState = (params) => {
    Object.keys(params).forEach(key => {
      this[key] = params[key];
    })
  }

  @action getListDatas = (params, path) => {
    if(!this.defalutJoinerList) {
      this.defalutJoinerList = new ListViewPage.Store({ route: path || this.path });
    }
    try {
      let options = {
        method: 'GET',
        url: `/api/cowork/type/getCoworkTypeShareList`,
        params
      };
      const listLoading = () => {this.listLoading = false}
      this.listLoading = true
      // 清除列表分页数据
      this.defalutJoinerList.clearData();
      Tools.callApi(options).then(
        action('fetchSuccess', (res) => {
          this.defalutJoinerList.getData({ dataKey: res.sessionkey }, listLoading, true)
        })
      )
    } catch (error) {
      this.listLoading = false
    }
  }
}